<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Basic editor functionality tests</title>
	<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
	<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css" type="text/css" />
	<script src="http://code.jquery.com/qunit/qunit-git.js"></script>
	<script src="qunit/connector.js"></script>
	<script type="text/javascript" src="qunit/runner.js"></script>
	<script type="text/javascript" src="js/utils.js"></script>
	<script type="text/javascript" src="js/tiny_mce_loader.js"></script>
	<script type="text/javascript" src="js/dsl/dsl.js"></script>
	<script type="text/javascript">
		QUnit.config.reorder = false;
		QUnit.config.autostart = false;

		module('Formatting - Robot Tests', {
			autostart: false,
			setup: function() {
				window.queue = new dsl.Queue();
			}
		});
		function checkExpectedAfterNewParagraph(expected) {
			robot.type('\n', false, function() {
				robot.type('g', false, function() {
					var actual = editor.getContent();
					var cleaned = actual.replace("<br />","");
					equal(cleaned, expected);
					start();
				}, editor.getBody())
			}, editor.getBody());
		}
		asyncTest('Should not be bold after turning off bold and going to a new paragraph', function() {
			editor.setContent('<p><strong>text</strong></p>');
			// in order for the robot to work well, we need to focus the editor before performing selection on it.
			editor.focus();
			setSelection("strong",4);
			editor.execCommand("Bold");
			var expected = '<p><strong>text</strong></p>\n<p>g</p>';
			checkExpectedAfterNewParagraph(expected);
		});
		
		asyncTest('Format with nested formatting turned off handled correctly', function(){
			editor.setContent('<p><strong>bold<em>italic<span style="text-decoration: underline;">under</span></em></strong></p>');
			editor.focus();
			setSelection("span",5);
			editor.execCommand("Italic");
			var expected ='<p><strong>bold<em>italic<span style="text-decoration: underline;">under</span></em></strong></p>\n<p><strong><span style="text-decoration: underline;">g</span></strong></p>';
			checkExpectedAfterNewParagraph(expected);
		});

		asyncTest('Format selection over two lines', function(){
			editor.setContent("<div id='a'>one</div><div id='b'>two</div>");
			editor.focus();
			setSelection('#a', 0, '#b', 0);
			editor.execCommand('formatBlock', false, 'h1');
			equal(editor.dom.select('#a')[0].tagName, 'H1');
			equal(editor.dom.select('#b')[0].tagName, 'DIV');
			start();
		});

		var initTinyFunction = function(){
			tinyMCE.init({
				mode : "exact",
				elements : "elm1",
				cleanup: true,

				add_unload_trigger : false,
				plugins: "table",
				init_instance_callback : function(ed) {
					editor = ed;

				}
			});
		};
	</script>
</head>
<body>
<h1 id="qunit-header">Plugin Dependency Functional tests</h1>

<h2 id="qunit-banner"></h2>

<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="content">
	<textarea id="elm1" name="elm1"></textarea>

	<div>
		<a href="javascript:alert(tinymce.EditorManager.get('elm1').getContent({format : 'raw'}));">[getRawContents]</a>
		<a href="javascript:alert(tinymce.EditorManager.get('elm1').getContent());">[getContents]</a>
	</div>
</div>
<script type="text/javascript" language="JavaScript" src="jsrobot/robot.js"></script>
<script>
	initWhenTinyAndRobotAreReady(initTinyFunction);
</script>
</body>
</html>
